/**
 * 
 */
package test.gm

import junit.framework.TestCase
import org.juiceshop.gm.*
/**
 * @author jst
 *
 */
public class KeySignatureTest extends TestCase{
	
	KeySignature ks
	
	static int C=60;
	static int Csharp=61;
	static int Dflat=61;
	static int D=62;
	static int Dsharp=63;
	static int Eflat=63;
	static int E=64;
	static int F=65;
	static int Fsharp=66;
	static int Gflat=66;
	static int G=67;
	static int Gsharp=68;
	static int Aflat=68;
	static int A=69;
	static int Asharp=70;
	static int Bflat=70;
	static int B=71;
	
	void testBasis() {
		assertEquals KeySignature.major('C'),KeySignature.major(C)
	}
	
	void testScale1 () {
		ks = KeySignature.major(C) // C-major
		assertEquals B-12, ks.scale(C,-1)         // C->B
		assertEquals D, ks.scale(C,+1)            // C->D
		assertEquals C, ks.scale(Csharp,-1)       // C#->C(=B#)
		assertEquals Dsharp, ks.scale(Csharp,+1)  // C#->D#
        assertEquals A-12, ks.scale(B-12,-1)      // B->A
        assertEquals C, ks.scale(B-12,+1)         // B->C
        assertEquals Gsharp-12, ks.scale(Asharp-12,-1) // A#->G#
        assertEquals C, ks.scale(Asharp-12,+1)    // A#->C(=B#)
	}
	
    void testScale2 () {
        ks = KeySignature.major(G) // G-major
        assertEquals Fsharp, ks.scale(G,-1) // G->F#
        assertEquals A, ks.scale(G,+1) // G->A
        assertEquals G, ks.scale(Gsharp,-1) // G#->G(=F##)
        assertEquals Asharp, ks.scale(Gsharp,+1) // G#->A#
        assertEquals E, ks.scale(Fsharp,-1) // F#->F(=E#)
        assertEquals G, ks.scale(Fsharp,+1) // F#->G
        assertEquals Dsharp, ks.scale(F,-1) // F(=E#)->D#
        assertEquals G, ks.scale(F,+1) // F(=E#)->G(=F##)
    }
	
    void testScale3 () {
        ks = KeySignature.major(F)  // F-major
        assertEquals E, ks.scale(F,-1) // F->E
        assertEquals G, ks.scale(F,+1) // F->G
        assertEquals E, ks.scale(Gflat,-1) // Gb->E(=Fb)
        assertEquals Aflat, ks.scale(Gflat,+1) // Gb->Ab
        assertEquals D, ks.scale(E,-1) // E->D
        assertEquals F, ks.scale(E,+1) // E->F
        assertEquals Dflat, ks.scale(Eflat,-1) // Eb->Db
        assertEquals E, ks.scale(Eflat,+1) // Eb->E(=Fb)
        
        assertEquals Bflat-12, ks.scale(C,-1)   // C->Bb
        assertEquals D, ks.scale(C,+1)          // C->D
        assertEquals A-12, ks.scale(B-12,-1)      // B(=Cb)->A(Bbb)
        assertEquals Dflat, ks.scale(B-12,+1)      // B(=Cb)->Db
        assertEquals A-12, ks.scale(Bflat-12,-1)// Bb->A
        assertEquals C, ks.scale(Bflat-12,+1)    // Bb->C
    }

    void testAdjust() {
    	ks = KeySignature.major(G)
		assertEquals Fsharp, ks.adjust(F)
		assertEquals G, ks.adjust(G)
		assertEquals Fsharp, ks.adjust(Fsharp)
		assertEquals F, ks.natural(Fsharp)
		assertEquals G, ks.natural(G)
		
        ks = KeySignature.major(F)
        assertEquals Bflat, ks.adjust(B)
        assertEquals F, ks.adjust(F)
        assertEquals Bflat, ks.adjust(Bflat)
        assertEquals B, ks.natural(Bflat)
        assertEquals F, ks.natural(F)
    }
}
